package com.invite.me.ui.cehualan.fragment;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.invite.me.R;
import com.invite.me.base.BaseFragment;
import com.invite.me.beans.adpater.InformationAdpater;
import com.invite.me.beans.presenter.InformationBeiyaoyuePresenter;
import com.invite.me.beans.res.InformationmyzlBean;
import com.invite.me.ui.yaoyue.InviteRecordDetailByyActivity;
import com.invite.me.wlqq.Contract;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

public class InFormationBeiYaoyueFragment extends BaseFragment implements Contract.BaseView{
    List<InformationmyzlBean.DataBean> datalist=new ArrayList<>();
    InformationAdpater informationAdpater;

    private SmartRefreshLayout myxiangqinsmartrefresh;
    private RecyclerView yaoyuerecyclerview;
    InformationBeiyaoyuePresenter informationPresenter;



    @Override
    protected void initView(View view) {
        informationPresenter=new InformationBeiyaoyuePresenter(this);
        informationPresenter.tijiaoshimingrenzheng("All","",10,0,"dis");

        yaoyuerecyclerview = view.findViewById(R.id.yaoyuerecyclerview);
        myxiangqinsmartrefresh = view.findViewById(R.id.myxiangqinsmartrefresh);
        myxiangqinsmartrefresh.setEnableRefresh(false);//是否启用下拉刷新功能
        myxiangqinsmartrefresh.setEnableLoadMore(true);//是否启用上拉加载功能
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        yaoyuerecyclerview.setLayoutManager(layoutManager);
        informationAdpater=new InformationAdpater(R.layout.information_adpater,datalist);
        yaoyuerecyclerview.setAdapter(informationAdpater);

        informationAdpater.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String id = datalist.get(position).getId();
                String state = datalist.get(position).getState();
                String type = datalist.get(position).getType();

                //被邀约
                Intent jilu=new Intent(getActivity(), InviteRecordDetailByyActivity.class);
                jilu.putExtra("state",state);
                jilu.putExtra("id",id);
                startActivity(jilu);




            }
        });




    }

    @Override
    protected void loadData() {

    }

    @Override
    protected int getFrgamentLayoutId() {
        return R.layout.framentinformationbeiyaoyue;
    }

    @Override
    public void setPresenter(Contract.BasePresenter basePresenter) {
        if (informationPresenter instanceof Contract.BasePresenter) {
            this.informationPresenter = (InformationBeiyaoyuePresenter) basePresenter;
        }
    }

    @Override
    public void onDataSucess(Object o)   {
        if(o instanceof InformationmyzlBean){
            InformationmyzlBean informationmyzlBean= (InformationmyzlBean) o;
            if(informationmyzlBean.getCode()==1000){
                datalist.addAll(informationmyzlBean.getData());
                informationAdpater.notifyDataSetChanged();

            }


        }
    }

    @Override
    public void onDataFaile(Object o) {

    }

    @Override
    public void onComplete() {

    }
}